-- simple case
CREATE TABLE t1 ( a INT PRIMARY KEY)
GO

CREATE TABLE t2 ( a INT REFERENCES t1(a))
GO


INSERT INTO t1 VALUES(1)
GO

INSERT INTO t2 VALUES(1)
GO


-- test TSQL specific types

CREATE TABLE t3 ( a UNIQUEIDENTIFIER PRIMARY KEY)
GO

CREATE TABLE t4 ( a UNIQUEIDENTIFIER REFERENCES t3(a))
GO

INSERT INTO t3 VALUES('123e4567-e89b-12d3-a456-426614174000')
GO

INSERT INTO t4 VALUES('123e4567-e89b-12d3-a456-426614174000')
GO



CREATE TABLE t5 (a SQL_VARIANT PRIMARY KEY)
GO

CREATE TABLE t6 (a SQL_VARIANT REFERENCES t5(a))
GO

INSERT INTO t5 VALUES('123')
GO

INSERT INTO t6 VALUES('123')
GO


-- other scenarios may trigger modified codes

CREATE TABLE t7 ( a INT PRIMARY KEY)
GO

CREATE TABLE t8 ( a INT REFERENCES t7(a) ON DELETE RESTRICT)
GO


INSERT INTO t7 VALUES(1)
GO

INSERT INTO t8 VALUES(1)
GO

DELETE FROM t7 WHERE a = 1
GO


-- drop tables (dependent table first)
DROP TABLE t2
GO

DROP TABLE t1
GO

DROP TABLE t4
GO

DROP TABLE t3
GO

DROP TABLE t6
GO

DROP TABLE t5
GO

DROP TABLE t8
GO

DROP TABLE t7
GO

